﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class Main_Accounts_VoucherFormatDetails : System.Web.UI.Page
{
    Datautility DU = new Datautility();
    string strSql = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["ParentId"] != null)
            {
                _BindDataList(Request.QueryString["ParentId"].ToString());
                hidParentId.Value = Request.QueryString["ParentId"].ToString();                
            }
        }
    }
    private void _BindDataList(string strParentTypeId)
    {
        if (strParentTypeId != string.Empty)
        {
            SqlParameter[] sqlpara = {
                                         new SqlParameter("@ParentTypeID",strParentTypeId),
                                         new SqlParameter("@ModuleType","1")
                                     };

            DataTable DTFormat = DU.getdatausingprocedure("USP_Get_Transaction_By_ParentTypeID",sqlpara);
            datalistDisplay.DataSource = DTFormat;
            datalistDisplay.DataBind();
            _BindDynamicHyperLink(strParentTypeId);
        }
    }
    private void _BindDynamicHyperLink(string strParentTypeId)
    {
        if (strParentTypeId != string.Empty)
        {
            foreach (DataListItem item in datalistDisplay.Items)
            {
                string strPageName = string.Empty;
                HiddenField hidTypeId = (HiddenField)item.FindControl("hidTypeId");
                HyperLink hyperVoucher = (HyperLink)item.FindControl("hyperVoucher");
                if (strParentTypeId == "1")
                {
                    strPageName = "Contra.aspx";
                    pagehead.HeadingText = "Contra Menu";
                }
                else if (strParentTypeId == "2")
                {
                    strPageName = "CreditNote.aspx";
                    pagehead.HeadingText = "Credit Note Menu";
                }
                else if (strParentTypeId == "3")
                {
                    strPageName = "DebitNote.aspx";
                    pagehead.HeadingText = "Debit Note Menu";
                }
                else if (strParentTypeId == "4")
                {
                    strPageName = "Journal.aspx";
                    pagehead.HeadingText = "Journal Menu";
                }
                else if (strParentTypeId == "6")
                {
                    strPageName = "Payment.aspx";
                    pagehead.HeadingText = "Payment Menu";
                }
                else if (strParentTypeId == "7")
                {
                    strPageName = "Purchase.aspx";
                    pagehead.HeadingText = "Purchase Menu";
                }
                else if (strParentTypeId == "8")
                {
                    strPageName = "PurchaseReturn.aspx";
                    pagehead.HeadingText = "Purchase Return Menu";
                }
                else if (strParentTypeId == "9")
                {
                    strPageName = "Receipt.aspx";
                    pagehead.HeadingText = "Receipt Menu";
                }
                else if (strParentTypeId == "10")
                {
                    strPageName = "Sale.aspx";
                    pagehead.HeadingText = "Sale Menu";
                }
                else if (strParentTypeId == "11")
                {
                    strPageName = "SaleReturn.aspx";
                    pagehead.HeadingText = "Sale Return Menu";
                }
                hyperVoucher.NavigateUrl = strPageName + "?TypeId=" + hidTypeId.Value;
            }
        }
    }
    
}
